//
//  CustomNavigationController.m
//  DPGJ
//
//  Created by ZhuoLaiQiang@Gmail.com on 11-11-17.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "CustomNavigationController.h"
#import <QuartzCore/QuartzCore.h>
#import "CONSTS.h"

@implementation UINavigationBar (CustomNavigationBar)

- (void)drawRect:(CGRect)rect
{
    UIImage *image = [UIImage imageNamed: @"nav_bg.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height)];
    self.tintColor = NAVIGATION_TINT_COLOR;
}

@end

@implementation CustomNavigationController


- (void)dealloc
{    
    [super dealloc];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    float version = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (version >= 5.0)
    {
        /* ios5/xcode4.2 以下不支持次方法 */
        [self.navigationBar setBackgroundImage: [UIImage imageNamed: @"nav_bg.png"] forBarMetrics: UIBarMetricsDefault];
        /********************/
        
        self.navigationBar.tintColor = NAVIGATION_TINT_COLOR;
    }
    self.navigationBar.backgroundColor = [UIColor whiteColor];
    [self.view setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"main_bg.png"]]];
    
//    self.navigationBar.layer.shadowOffset = CGSizeMake(0, 3);
//    self.navigationBar.layer.shadowOpacity = 0.4;
//    self.navigationBar.layer.shadowColor = [UIColor blackColor].CGColor;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

/*
#pragma mark - UINavigationControllerDelegate
#define COVER_VIEW_TAG 10982
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    NSString *topViewController = NSStringFromClass([navigationController.topViewController class]);
    NSString *visibleViewController = NSStringFromClass([navigationController.visibleViewController class]);
    
    ITTDINFO(@"\n topViewController = %@\n visibleViewController = %@", topViewController, visibleViewController);
    ITTDINFO(@"%d", [[navigationController viewControllers] count]);
    
    static int sign = 0;
    
    if ([topViewController isEqualToString:@"RootViewController"] && sign)
    {
        UIView *coverView = [[[UIView alloc] initWithFrame: [UIScreen mainScreen].bounds] autorelease];
        coverView.tag = COVER_VIEW_TAG;
        coverView.backgroundColor = [UIColor blackColor];
        coverView.alpha = 0.0f;
        [navigationController.view.window addSubview: coverView];

        [UIView beginAnimations: nil context: nil];
        [UIView setAnimationDuration: 0.2];
  
        
                coverView.alpha = 1.0f;
        
        [UIView commitAnimations];
    }
    
    sign = 1;
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
}

*/

@end
